<?php

include 'conn.php';
$slAct = intval($_SESSION['SelectedActivity']);
$CentreName = $_SESSION['centreName'];
$username = $_SESSION["loginusername"];
/*
  $count = 0;
  foreach ($_POST['cbpa'] as $check) {
  echo $check;
  $count++;
  }
  list($one, $two) = explode("-", "44-xkIolspO", 2);
  $perfCount = 1;
  for ($i = 1; $i <= $count; $i++) {
  if (!empty($_POST['cbpe' . $i])) {
  foreach ($_POST['cbpe' . $i] as $perf) {
  list($one, $two) = explode("-", $perf, 2);
  echo $one;
  echo "\t".$two;
  }
  }

  } */
$sqlActName = mysql_query("Select ActivityName from activity where ActivityId=$slAct");
$row = mysql_fetch_array($sqlActName);
$actName = $row['ActivityName'];
if (!empty($_POST['cbpa'])) {
    foreach ($_POST['cbpa'] as $check) {
        list($nric, $count) = explode("-", $check, 2);
        if (!empty($_POST['cbpe' . $count])) {
            foreach ($_POST['cbpe' . $count]as $perf) {
                list($one, $two) = explode("-", $perf, 2);
                $sql = mysql_query("INSERT INTO `activityrecord`( `NRIC`, `CentreId`, `Date`, `ActivityId`, `AuditRecords`, `Performance`) VALUES ('" . $check . "',(Select CentreId from Centre where CentreName='" . $CentreName . "'),NOW()," . $slAct . ",'" . $username . "'," . $one . ")");
            }
        }
        $count++;
    }
    if ($sql) {
        echo"<script>";
        echo "alert('Activity Attendance for $actName has been taken!');";
        echo "</script>";
    }
} else {
    echo "<script>";
    echo "alert('Please select the checkboxes!')";
    echo "</script>";
}
/*
  $username = $_SESSION["loginusername"];
  $count = 1;
  foreach ($_POST['cbpa'] as $check) {

  if (!empty($_POST['cbpe' . $count])) {
  foreach ($_POST['cbpe' . $count] as $perf) {
  list($one, $two) = explode("-", $perf, 2);
  if ($two == $check) {
  $sql = mysql_query("INSERT INTO `activityrecord`( `NRIC`, `CentreId`, `Date`, `ActivityId`, `AuditRecords`, `Performance`) VALUES ('" . $check . "',(Select CentreId from Centre where CentreName='" . $CentreName . "'),NOW()," . $slAct . ",'" . $username . "'," . $one . ")");
  }
  }
  }
  $count++;

  }

  echo"<script>";
  echo "alert('Activity Attendance for has been taken!');";
  echo "</script>";
 * */
?>